package java8;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;

public class Grab {

    public static void main(String[] args) throws IOException {
        /*Document doc = Jsoup.connect("http://www.baidu.com").get();
        String title = doc.title();
        System.out.println(title);*/
    }

    public static String getPageWaitJS (String url) throws IOException {
        WebClient webClient = new WebClient();
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        HtmlPage page = webClient.getPage(url);
        webClient.waitForBackgroundJavaScript(3 * 1000);
        String pageXml = page.asXml(); //以xml的形式获取响应文本
        return pageXml;
    }

}
